const path = require('path');
// 引入html-webpack-plugin
const htmlWebpackPlugin=require('html-webpack-plugin');
// 热更新第二步
const webpack=require('webpack');

// vue-loader插件
const { VueLoaderPlugin } = require('vue-loader');

module.exports = {
  mode: 'development',    //production
  entry: path.resolve(__dirname, './src/main.js'),
  // entry:["@babel/polyfill",path.resolve(__dirname, './src/main.js')],
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js'
  },
  // webpack-dev-server的配置节点
  devServer:{
    open:true,          //自动打开浏览器
    port:3000,          //指定端口
    contentBase:'src',  //指定服务器名根目录
    hot:true,    //热更新第一步
    progress:false,  //显示打包进度
    quiet:false,
    proxy: {
      '/api': {
          target: 'http://www.duans.top/freeApi',
          pathRewrite: {'^/api' : ''},
          changeOrigin: true,     // target是域名的话，需要这个参数，
          secure: false
      }
    }
  },
  plugins:[
    // 热更新第三步
    new webpack.HotModuleReplacementPlugin(),
    new htmlWebpackPlugin({
        template:path.join(__dirname,'src/index.html'), //模板文件的目录+文件名
        filename:'index.html'     //内存中的文件名
    }),
    // vue-loader插件
    new VueLoaderPlugin()

  ],
  module:{
    rules:[
      // css打包配置
      {test:/\.css$/,use:['style-loader','css-loader']},
      // less配置
      {test:/\.less$/,use:['style-loader','css-loader','less-loader']},
      //打包scss
      {test:/\.scss$/,use:['style-loader','css-loader','sass-loader']},
      //打包图片
      {
        test:/\.(png|gif|jpg|jpeg|bmp)$/,
        use:'url-loader?limit=2048U&name=[hash:8]-[name].[ext]'
      },
      //打包字体文件
      {
        test:/\.(ttf|eot|svg|woff|woff2|otf)$/, 
        use: 'url-loader'
      },
      //babel配置
      {
        test:/\.js$/,
        use:'babel-loader',
        exclude:['/node_modules/']   //不需要转换的js文件
      },
      //打包.vue
      {
        test:/\.vue$/,
        use:'vue-loader'
      }
    ]
  },
  resolve:{
    alias:{
      "vue$":"vue/dist/vue.js"
    }
  }
 
};